<template>
  <div>
    <ul>
      <li>
        <router-link
          active-class="active"
          exact-active-class="exact"
          to="/contacts/allcontacts"
          >ALL_contacts</router-link
        >
      </li>
      <li>
        <router-link
          active-class="active"
          exact-active-class="exact"
          to="/contacts/alice"
          >Alice</router-link
        >
      </li>
      <li>
        <router-link
          active-class="active"
          exact-active-class="exact"
          to="/contacts/bob"
          >Bob</router-link
        >
      </li>
    </ul>
    <button @click="btnFn">随机显示</button>

    <div>
      <router-view></router-view>
    </div>
  </div>
</template>

<script>
export default {
  data() {
    return {
      arr: ["/contacts/allcontacts", "/contacts/alice", "/contacts/bob"],
    };
  },
  methods: {
    btnFn() {
      let tarPath = this.arr[Math.floor(Math.random() * this.arr.length)];
      if (this.$route.path !== tarPath) {
        this.$router.replace(tarPath);
      }
    },
  },
};
</script>

<style scoped>
.active {
  color: pink;
}
</style>